<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Hash;
class LoginController extends Controller
{
    public function getIndex(){
        //进入登录界面
        return view('admin.admin.login');
    }

    public function postDologin(Request $request){
        // dd($request->all());
        //根据用户名查询数据库信息
        $data = DB::table('tbl_admin_user') -> where('username',$request -> input('username'))->first();
        //把输入的的用户密码通过哈希加密，与数据库核对是否一致
        $res = Hash::check($request -> input('password'),$data['password']);
        // dd($data);exit();
        // 将logo查询出来 并写入session
         $configdata = DB::table('tbl_webconfg')->first();
        if($res){
            session(['username'=>$data['username'],'id'=>$data['id'],'logo'=>$configdata['logo'],'copyright'=>$configdata['copyright']]);
            return redirect('/admin') -> with('success','登录成功 ! ');
        }else{
            return back() -> withInput() -> with('error','账号或密码错误 ! ');
        }
    }

    public function  getLoginout(){
        session(['id'=>'']);
        return redirect('/admin');
    }

}
